package com.shux.usermanager.biz.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.DecimalFormat;

/**
 **********************************************
 *  描述：
 * Simba.Hua
 * 2017年8月20日
 **********************************************
**/
public class TestCopyFile  extends Thread{
    private String srcpath;
    private String destPath;
    public static void main(String[] args) {
        TestCopyFile l_testCopyFile1 = new TestCopyFile("D:\\test\\testsrc1.txt","D:\\test\\testdest1.txt");
        TestCopyFile l_testCopyFile2 = new TestCopyFile("D:\\test\\testsrc1.txt","D:\\test\\testdest2.txt");
        l_testCopyFile1.start();
        l_testCopyFile2.start();

    }
    public TestCopyFile(String srcpath,String destPath){
        this.srcpath = srcpath;
        this.destPath = destPath;
    }
    

    @Override
    public void run() {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(new File(srcpath));
            fos = new FileOutputStream(new File(destPath));
            long fileLength = new File(srcpath).length();
            byte[] bytes = new byte[1024];
            int len ;
            double temp = 0;
            DecimalFormat df = new DecimalFormat("##.00%");
            while((len = fis.read(bytes)) != -1 ){
                fos.write(bytes, 0, len);
                temp = ++len ;
               double d = len/temp;
               System.out.println("已完成复制"+ new File(destPath).getName()+"文件"+ df.format(d));
               
            }
            System.out.println("已完成复制"+ new File(destPath).getName()+"文件");
            
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                if (fis != null){
                    fis.close();
                }
                if (fos != null){
                    fos.close(); 
                }
                
            } catch (Exception e2) {
                // TODO: handle exception
            }
        }
       
        
    }
    
    
    

}
